﻿using System;
using System.Collections.Generic;
using System.IO.IsolatedStorage;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GoStats.Model

{
    public class Persist
    {

        private String username;
        private String password;

        public String Username
        {
            get { return username; }
            set { username = value; }
        }

        public String Password
        {
            get { return password; }
            set { password = value; }
        }

        public void PersistLogin()
        {
            if (IsolatedStorageSettings.ApplicationSettings.Contains("Username"))
            {
                IsolatedStorageSettings.ApplicationSettings["Username"] = Username;
            }
            else
            {
                IsolatedStorageSettings.ApplicationSettings.Add("Username", Username);
            }

            if (IsolatedStorageSettings.ApplicationSettings.Contains("Password"))
            {
                IsolatedStorageSettings.ApplicationSettings["Password"] = Password;
            }
            else
            {
                IsolatedStorageSettings.ApplicationSettings.Add("Password", Password);
            }

            IsolatedStorageSettings.ApplicationSettings.Save();
        }

        public Boolean Load()
        {
            String outs;
            if (IsolatedStorageSettings.ApplicationSettings.TryGetValue<String>("Username", out outs))
            {
                Username = outs;
            }
            else return false;
            if (IsolatedStorageSettings.ApplicationSettings.TryGetValue<String>("Password", out outs))
            {
                Password = outs;
            }
            else return false;

            return true;

        }

    }
}
